<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>News</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<link type="text/css" rel="stylesheet" href="css/comment.css" />
	<link type="text/css" rel="stylesheet" href="../../css/pepper-grinder/jquery-ui-1.8.16.custom.css" />
	<link type="text/css" rel="stylesheet" href="../../css/popeScroll.css" />
	<link type="text/css" rel="stylesheet" href="../../css/popeWin.css" />
	<script type="text/javascript" src="../../js/jquery.min.js"></script>
	<script type="text/javascript" src="../../js/jquery-ui-1.8.16.custom.min.js"></script>
	<script type="text/javascript" src="../../js/jquery.mousewheel.min.js"></script>
	<script type="text/javascript" src="../../js/popeScroll.js"></script>
	<script type="text/javascript" src="../../js/popeWin.js"></script>
	
	<script language="JavaScript" type="text/JavaScript">
		var objid;
		var user;
		$(document).ready(function() {
			var cururl = window.location.href;
			objid = cururl.split('=')[1];
			
			$(window).resize(function() {
				refresh();
			});	
			refresh();
			$.getJSON("account_getUser.do",null,function(json){
				user = json;
			});
			
			$.getJSON("comment_getCommentListByOjbid.do",{objid:objid,hasSub:false},function(json){
				if(json==null){return;}
				for(var i=0;i<json.length;i++){
					var obj = json[i];
					var headimgpath = obj.userimgpath;
					if(headimgpath==null||headimgpath==""){
						headimgpath = "../../image/index/noimage.gif";
					}else{
						headimgpath = "../../" + headimgpath;
					}
					var divstr = getCommentDiv(obj.id,obj.content,obj.username,obj.createtime,headimgpath);
					$("#content").append(divstr);
					
					
					$.getJSON("comment_getSubCommentListById.do",{commentid:obj.id},function(subjson){
						
						for(var j=0;j<subjson.length;j++){
							var subobj = subjson[j];
							var parentid = subobj.commentid;
							
							var subheadimgpath = subobj.userimgpath;
							if(subheadimgpath==null||subheadimgpath==""){
								subheadimgpath = "../../image/index/noimage.gif";
							}else{
								subheadimgpath = "../../" + subheadimgpath;
							}
							var subdivstr = getSubCommentDiv(subobj.id,subobj.content,subobj.username,subobj.createtime,headimgpath);
							$("#row_"+parentid).after(subdivstr);
						}
						
						refresh();
					});
					
					
				}
				
				
				refresh();
				
				
			});
			
			
			
			
			
		});
		function refresh(){
			var winheight = $(window).height();
			var winwidth = $(window).width();
			
			$("#bodydiv").css("height",winheight);
			
			$("#t").css("width",winwidth-46);
			$("#m").css("width",winwidth-46);
			var w = parseInt((winwidth-155)/2);
			$("#b1").css("width",w);
			if((w*2)<(winwidth-155)){
				$("#b2").css("width",w+1);
			}else{
				$("#b2").css("width",w);
			}
			
			
			
			$("#middle").css("height",winheight-67);
			
			$("#content").popeScroll({
				offset_top:-300,
				top:25,
				mousewheelBox:"box",
				nobar:true
			});
			
			
		}
		
		function addComment(ele){
			var eleid = ele.id;
			var divstr = '<div class="formbox">';
			divstr = divstr + '<div class="formtitle" >';
			divstr = divstr + '<div style="float:left;width:300px;color:#64b1f8;">请输入评论内容</div>';
			divstr = divstr + '<div style="float:left;width:40px;color:#64b1f8;cursor:pointer;" onclick="submitCommentForm(\'formtxt_'+eleid+'\');">确定</div>';
			divstr = divstr + '<div style="float:left;width:40px;color:#64b1f8;cursor:pointer;" onclick="closeForm(\''+eleid+'\');">取消</div>';
			divstr = divstr + '</div>';
			divstr = divstr + '<div class="formcontent">';
			divstr = divstr + '<textarea id="formtxt_'+eleid+'" class="formtxt"></textarea>';
			divstr = divstr + '</div>';
			divstr = divstr + '</div>';
			
			
				
			$.popeWinMini({
				id:eleid,
				width:420,
				height:150,
				content:divstr
			});
			
			
		}
		
		function submitCommentForm(id){
			var val = $("#"+id).val();
			var commentid;
			
			if(id!="formtxt_tjpl"){
				commentid = id.split("_")[1];
			}
			$.getJSON("comment_addComment.do",{objid:objid,content:val,commentid:commentid},function(json){
				
				if(id=="formtxt_tjpl"){
					var headimgpath = user.photo;
					if(headimgpath==null||headimgpath==""){
						headimgpath = "../../image/index/noimage.gif";
					}else{
						headimgpath = "../../" + headimgpath;
					}
					var divstr = getCommentDiv(json.id,json.content,user.realName,json.createtime,headimgpath);
					
					$("#content").prepend(divstr);
					$.popeWinMiniClose({
						id:"tjpl"
					});
				}else{
					var headimgpath = user.photo;
					if(headimgpath==null||headimgpath==""){
						headimgpath = "../../image/index/noimage.gif";
					}else{
						headimgpath = "../../" + headimgpath;
					}
					var subdivstr = getSubCommentDiv(json.id,json.content,user.realName,json.createtime,headimgpath);
					$("#row_"+commentid).after(subdivstr);
					$.popeWinMiniClose({
						id:commentid
					});
				}				
				
			});
			
			
		}
		function closeForm(id){
			$.popeWinMiniClose({
				id:id
			});
		}
		
		function getCommentDiv(commentid,content,username,createtime,headimgpath){
			
			var divstr = '<div id="row_'+commentid+'" class="row">';
			divstr = divstr + '<div class="headimgdiv">';
			divstr = divstr + '<img id="'+commentid+'" title="点击评论" onclick="addComment(this);" src="'+headimgpath+'" style="width:60px;height:60px;cursor:pointer;" />';
			divstr = divstr + '</div>';
			divstr = divstr + '<div class="item1">';
			divstr = divstr + '<div class="con">'+content+'</div>';
			divstr = divstr + '<div class="time">'+username+','+createtime+'</div>';
			divstr = divstr + '</div>';
			divstr = divstr + '</div>';
			return divstr;
		}
		
		function getSubCommentDiv(commentid,content,username,createtime,headimgpath){
			var subdivstr = '<div id="row_'+commentid+'" class="row">';
			subdivstr = subdivstr + '<div class="headimgdiv2">';
			subdivstr = subdivstr + '<img id="'+commentid+'" src="'+headimgpath+'" style="width:60px;height:60px;cursor:pointer;padding-left:5px;" />';
			subdivstr = subdivstr + '</div>';
			subdivstr = subdivstr + '<div class="item2">';
			subdivstr = subdivstr + '<div class="con2" >'+content+'</div>';
			subdivstr = subdivstr + '<div class="time">'+username+','+createtime+'</div>';
			subdivstr = subdivstr + '</div>';
			subdivstr = subdivstr + '</div>';
			return subdivstr
		}
		
		
	</script>
</head>
<body style="background-color=transparent;width:100%;margin-left:0px;margin-top:0px;">
	<div id="bodydiv" style="float:left;width:100%;">
		<div id="top" style="float:left;width:100%;">
			<div style="float:left;background:url(image/lt.png);width:23px;height:23px;"></div>
			<div id="t" style="float:left;background:url(image/t.png);width:600px;height:23px;"></div>
			<div style="float:right;background:url(image/rt.png);width:23px;height:23px;"></div>
		</div>
		<div id="middle" style="float:left;width:100%;height:400px;">
			<div style="float:left;background:url(image/l.png);width:23px;height:100%;"></div>
			<div id="m" style="float:left;background:url(image/c.png);width:600px;height:100%;">
				<div id="tool" style="width:100%;height:20px;float:left;text-align:center;">
					<div id="tjpl" style="cursor:pointer;float:left;width:30%;margin-left:35%;" onclick="addComment(this)">点击添加评论</div>
					
				</div>
				<div id="box" style="width:90%;height:90%;margin-left:5%;margin-top:2%;float:left;overflow:hidden;">
					<div id="content" style="width:100%;float:left;">
						
					</div>
					
					
					
				</div>
			</div>
			<div style="float:right;background:url(image/r.png);width:23px;height:100%;"></div>
		</div>
		<div id="bottom" style="float:left;width:100%;">
			<div style="float:left;background:url(image/lb.png);width:23px;height:44px;"></div>
			<div id="b1" style="float:left;background:url(image/b.png);width:245px;height:44px;"></div>
			<div style="float:left;background:url(image/b2.png);width:109px;height:44px;"></div>
			<div id="b2" style="float:left;background:url(image/b.png);width:246px;height:44px;"></div>
			<div style="float:right;background:url(image/rb.png);width:23px;height:44px;"></div>
		</div>
		
		
	</div>
</body>
</html>